var vectPid, mrkvPid, maskPid, markPid, newPid, playPid, x16Pid, b16Pid: Integer; xlate16uto8Pid, ymin, ymax: integer; kmin, kdelta, knum, koverlap: integer; kernelPid, smoothPid: integer; fore,foredef: integer; std16uto8Pid: integer; procedure Std16To8; begin RequiresUser('pixel16u', 1); SaveState; SetNewSize(256, 256); SetBackgroundColor(0); MakeNewWindow('BioVision 16 to 8 conversion table'); xlate16uto8Pid := pidNumber; linLUT16uto8(xlate16uto8Pid, 0, 65535, 0, 255); RestoreState; end; macro 'Dispose All ** CAREFUL **'; begin DisposeAll; end; macro '-)'; begin end; {Global variable values are lost when macros are reloaded.} {This is mainly for use during macro development.} macro 'Create global variable save image'; begin setNewSize(32, 32); MakeNewWindow('Global Variables'); end; macro 'Save global variables'; var savePid, globalPid: integer; begin savePid := pidNumber; SelectWindow('Global Variables'); globalPid := pidNumber; PutPixVec32s(globalPid, 1, vectPid); PutPixVec32s(globalPid, 2, mrkvPid); PutPixVec32s(globalPid, 3, maskPid); PutPixVec32s(globalPid, 4, markPid); PutPixVec32s(globalPid, 5, newPid); PutPixVec32s(globalPid, 6, playPid); PutPixVec32s(globalPid, 7, x16Pid); PutPixVec32s(globalPid, 8, xlate16uto8Pid); PutPixVec32s(globalPid, 9, ymin); PutPixVec32s(globalPid, 10, ymax); PutPixVec32s(globalPid, 11, kmin); PutPixVec32s(globalPid, 12, kdelta); PutPixVec32s(globalPid, 13, knum); PutPixVec32s(globalPid, 14, koverlap); PutPixVec32s(globalPid, 15, kernelPid); PutPixVec32s(globalPid, 16, b16Pid); PutPixVec32s(globalPid, 17, smoothPid); SelectPic(savePid); end; macro 'Restore global variables'; var savePid, globalPid: integer; begin savePid := pidNumber; SelectWindow('Global Variables'); globalPid := pidNumber; vectPid := GetPixVec32s(globalPid, 1); mrkvPid := GetPixVec32s(globalPid, 2); maskPid := GetPixVec32s(globalPid, 3); markPid := GetPixVec32s(globalPid, 4); newPid := GetPixVec32s(globalPid, 5); playPid := GetPixVec32s(globalPid, 6); x16Pid := GetPixVec32s(globalPid, 7); xlate16uto8Pid := GetPixVec32s(globalPid, 8); ymin := GetPixVec32s(globalPid, 9); ymax := GetPixVec32s(globalPid, 10); kmin := GetPixVec32s(globalPid, 11); kdelta := GetPixVec32s(globalPid, 12); knum := GetPixVec32s(globalPid, 13); koverlap := GetPixVec32s(globalPid, 14); kernelPid := GetPixVec32s(globalPid, 15); b16Pid := GetPixVec32s(globalPid, 16); smoothPid := GetPixVec32s(globalPid, 17); if pidExists(savePid) then SelectPic(savePid); end; macro 'Front image is mask image'; begin maskPid := pidNumber; end; macro 'Front image is mark image'; begin markPid := pidNumber; end; macro 'Front image is 16 bit cropped stack'; begin vectPid := pidNumber; end; macro 'Front image is 16 to 8 conversion table'; begin xlate16uto8Pid := pidNumber; end; macro 'Front image is 8 bit display buffer'; begin playPid := pidNumber; end; macro 'Front image is 16 bit slice buffer'; begin x16Pid := pidNumber; end; macro 'Front image is background kernel'; begin kernelPid := PidNumber; kmin := getPixel(0, 0); kdelta := getPixel(0, 1); knum := getPixel(0, 2); koverlap := getPixel(0, 3); end; macro 'Front image is smoothing kernel'; begin smoothPid := PidNumber; end; procedure checkPids; var left, top, width, height: integer; begin RequiresUser('Pixel16u', 1); if not pidExists(maskPid) then begin PutMessage('Please run macro "Front image is mask image"'); Exit; end; if not pidExists(vectPid) then begin PutMessage('Please run macro "Front image is 16 bit cropped stack"'); Exit; end; if not pidExists(xlate16uto8Pid) then begin PutMessage('Please run macro "Front image is 16 to 8 conversion table"'); Exit; end; if not pidExists(playPid) then begin selectPic(maskPid); GetPicSize(width, height); SetNewSize(width, height); MakeNewStack('8 bit stack'); playPid := pidNumber; end; if not pidExists(x16Pid) then begin selectPic(maskPid); GetPicSize(width, height); SetNewSize(2 * width, height); MakeNewWindow('16 bit data buffer -- trash'); x16Pid := pidNumber; end; if not pidExists(b16Pid) then begin selectPic(maskPid); GetPicSize(width, height); SetNewSize(2 * width, height); MakeNewWindow('16 bit background -- trash'); b16Pid := pidNumber; end; if not pidExists(markPid) then begin selectPic(maskPid); GetPicSize(width, height); SetNewSize(width, height); MakeNewWindow('mark'); markPid := pidNumber; end; end; macro 'make 16 to 8 conversion table'; var i, j, x, y: integer; width, height: integer; inPid, min, max: integer; begin RequiresUser('pixel16u', 1); ymin := GetNumber('minimum 8 bit pixel value', 1); ymax := GetNumber('maximum 8 bit pixel value', 254); SaveState; inPid := pidNumber; minMax16u(inPid, min, max); min := GetNumber('minimum 16 bit pixel value', min); max := GetNumber('maximum 16 bit pixel value', max); SetNewSize(256, 256); SetBackgroundColor(0); MakeNewWindow('16 to 8 conversion table'); xlate16uto8Pid := pidNumber; linLUT16uto8(xlate16uto8Pid, min, max, ymin, ymax); end; macro 'convert packed 16 to 8 no offset'; var i, n: integer; begin CheckPids; selectPic(playPid); choosePic(vectPid); n := nSlices; resetCounter; linLUT16uto8(xlate16uto8Pid, 0, 8191, 0, 255); for i := 1 to n do begin choosePic(vectPid); chooseSlice(i); choosePic(playPid); if i > nSlices then addSlice; chooseSlice(i); CnvMsk16uTo8(vectPid, xlate16uto8Pid, maskPid, playPid); SelectAll; Measure; end; end; macro 'convert 16 to 8 no offset'; var i, n: integer; begin CheckPids; selectPic(playPid); choosePic(vectPid); n := nSlices; resetCounter; linLUT16uto8(xlate16uto8Pid, 0, 65535, 0, 255); SetOptions('Area,Mean,Std. Dev.'); for i := 1 to n do begin choosePic(vectPid); chooseSlice(i); choosePic(playPid); if i > nSlices then addSlice; chooseSlice(i); Cnvrt16uTo8(vectPid, xlate16uto8Pid, playPid); SelectAll; Measure; end; end; macro 'convert packed 16 to 8 with offset'; var i, n: integer; min,max: integer; begin CheckPids; selectPic(playPid); choosePic(vectPid); n := nSlices; resetCounter; for i := 1 to n do begin choosePic(vectPid); chooseSlice(i); choosePic(playPid); if i > nSlices then addSlice; chooseSlice(i); min := rMean[i] * 8192/256 - 1000; max := min + 4096; linLUT16uto8(xlate16uto8Pid, min, max, 0, 255); CnvMsk16uTo8(vectPid, xlate16uto8Pid, maskPid, playPid); end; end; macro 'convert 16 to 8 with offset'; var i, n: integer; min,max: integer; begin CheckPids; selectPic(playPid); killroi; choosePic(vectPid); killroi; n := nSlices; resetCounter; for i := 1 to n do begin choosePic(vectPid); chooseSlice(i); choosePic(playPid); if i > nSlices then addSlice; chooseSlice(i); min := (rMean[i]-2*rStdDev[i]) * 65536/256; max := (rMean[i]+6*rStdDev[i]) * 65536/256; linLUT16uto8(xlate16uto8Pid, min, max, 0, 255); Cnvrt16uTo8(vectPid, xlate16uto8Pid, playPid); end; end; macro 'stacktoMontage'; var i,n, stkPid, montPid: integer; width, height, perrow, percol, x, y: integer; begin n := nSlices; stkPid := pidNumber; GetPicSize(width, height); perrow := trunc(sqrt(n)); percol := trunc((n + perrow)/perrow); SetNewSize(width * perrow, height*percol); MakeNewWindow('montage'); montPid := PidNumber; x := 0; y := 0; for i := 1 to n do begin if x >= perrow then begin x := 0; y := y + 1; end; choosePic(stkPid); chooseSlice(i); selectAll; copy; choosePic(montPid); makeRoi(x * width, y * height, width, height); paste; setForegroundColor(255); moveto(x * width, y * height+10); write(i); x := x + 1; end; end; macro 'out dammed spot'; var i,n,x,y: integer; stkpid, newpid: integer; width, height: integer; begin stkpid := pidNumber; n := nSlices; getPicSize(width,height); setNewSize(width,height); makeNewStack('noSpot'); newPid := pidNumber; for i := 1 to n do begin choosePic(stkpid); selectslice(i); selectall; copy; choosePic(newPid); if i > nSlices then addslice; selectslice(i); paste; {makeOvalRoi(18,8,7,7);} makeOvalRoi(16,6,9,9); copy; {makeOvalRoi(25,8,7,7);} makeOvalRoi(24,6,9,9); paste; makeOvalRoi(22,4,11,11); reduceNoise; Smooth; end; end; macro 'out dammed 16 bit spot'; var i,n,x,y: integer; stkpid, newpid: integer; width, height: integer; begin stkpid := pidNumber; n := nSlices; getPicSize(width,height); setNewSize(width,height); makeNewStack('noSpot 16'); newPid := pidNumber; for i := 1 to n do begin choosePic(stkpid); selectslice(i); selectall; copy; choosePic(newPid); if i > nSlices then addslice; selectslice(i); paste; {makeOvalRoi(18,8,7,7);} makeRoi(16*2,6,18,9); copy; {makeOvalRoi(25,8,7,7);} makeRoi(24*2,6,18,9); paste; end; end; macro 'scaletoMontage'; var i,n, start, stkPid, montPid: integer; width, height, perrow, percol, x, y: integer; del1pid, del2pid: integer; scalex,scaley: real; begin n := nSlices; stkPid := pidNumber; GetPicSize(width, height); perrow := 5; percol := 6; perrow := 3; percol := 4; SetNewSize(640,480); scalex := 640 / (perrow*width); scaley := 480 / (percol * height); if scalex > scaley then scalex := scaley else scaley := scalex; MakeNewWindow('montage'); montPid := PidNumber; x := 0; y := 0; start := getnumber('start slice',1); for i := start to start+perrow*percol-1 do begin if x >= perrow then begin x := 0; y := y + 1; end; choosePic(stkPid); chooseSlice(i*7); killRoi; Duplicate('deleteme'); del1pid := pidNumber; Smooth; Smooth; ScaleAndRotate(scalex,scaley,0); del2pid := pidNumber; SelectAll; Copy; choosePic(montPid); makeRoi(x * width * scalex, y * height * scaley, width*scalex, height*scaley); paste; choosePic(del1pid); Dispose; choosePic(del2pid); Dispose; x := x + 1; end; end; macro 'scaletoMontage 512x480'; var i,n, start, stkPid, montPid: integer; width, height, perrow, percol, x, y: integer; del1pid, del2pid: integer; scalex,scaley: real; begin n := nSlices; stkPid := pidNumber; GetPicSize(width, height); perrow := 5; percol := 6; perrow := 3; percol := 4; SetNewSize(512,480); scalex := 512 / (perrow*width); scaley := 480 / (percol * height); if scalex > scaley then scalex := scaley else scaley := scalex; MakeNewWindow('montage'); montPid := PidNumber; x := 0; y := 0; start := getnumber('start slice',1); for i := start to start+perrow*percol-1 do begin if x >= perrow then begin x := 0; y := y + 1; end; choosePic(stkPid); chooseSlice(i*7); killRoi; Duplicate('deleteme'); del1pid := pidNumber; Smooth; Smooth; ScaleAndRotate(scalex,scaley,0); del2pid := pidNumber; SelectAll; Copy; choosePic(montPid); makeRoi(x * width * scalex, y * height * scaley, width*scalex, height*scaley); paste; choosePic(del1pid); Dispose; choosePic(del2pid); Dispose; x := x + 1; end; end; macro 'scaletoMontage 512x480 selected'; var i,n, start, stkPid, montPid: integer; width, height, perRow, perCol, x, y: integer; del1pid, del2pid: integer; scalex,scaley: real; begin rUser1[1] := 1; rUser1[2] := 3; rUser1[3] := 8; rUser1[4] := 46; rUser1[5] := 48; rUser1[6] := 59; rUser1[7] := 68; rUser1[8] := 70; rUser1[9] := 71; rUser1[10] := 80; rUser1[11] := 82; rUser1[12] := 87; n := nSlices; stkPid := pidNumber; GetPicSize(width, height); perRow := 3; perCol := 4; SetNewSize(512,480); scalex := 512 / (perrow*width); scaley := 480 / (percol * height); if scalex > scaley then scalex := scaley else scaley := scalex; MakeNewWindow('montage'); montPid := PidNumber; x := 0; y := 0; for i := 1 to perRow * perCol do begin if x >= perRow then begin x := 0; y := y + 1; end; choosePic(stkPid); chooseSlice(rUser1[i]); killRoi; Duplicate('deleteme'); del1pid := pidNumber; SetScaling('Bilinear,New Window'); ScaleAndRotate(scalex,scaley,0); del2pid := pidNumber; SelectAll; Copy; choosePic(montPid); makeRoi(x * width * scalex, y * height * scaley, width*scalex, height*scaley); paste; choosePic(del1pid); Dispose; choosePic(del2pid); Dispose; x := x + 1; end; end; macro 'selected Montage 512x480'; var i,n, start, stkPid, montPid: integer; width, height, perRow, perCol, x, y: integer; del1pid, del2pid: integer; scalex,scaley: real; begin rUser1[1] := 1; rUser1[2] := 3; rUser1[3] := 8; rUser1[4] := 46; rUser1[5] := 48; rUser1[6] := 59; rUser1[7] := 68; rUser1[8] := 70; rUser1[9] := 71; rUser1[10] := 80; rUser1[11] := 82; rUser1[12] := 87; n := nSlices; stkPid := pidNumber; GetPicSize(width, height); perRow := 3; perCol := 4; SetNewSize(512,480); scalex := 512 / (perrow*width); scaley := 480 / (percol * height); if scalex > scaley then scalex := scaley else scaley := scalex; MakeNewWindow('montage'); montPid := PidNumber; x := 0; y := 0; for i := 1 to perRow * perCol do begin if x >= perRow then begin x := 0; y := y + 1; end; choosePic(stkPid); chooseSlice(rUser1[i]); killRoi; SelectAll; Copy; choosePic(montPid); makeRoi(x * width * scalex + 5, y * height * scaley + 5, width, height); paste; x := x + 1; end; end; macro 'selected Montage 512x480 2x3'; var i,n, start, stkPid, montPid: integer; width, height, perRow, perCol, x, y: integer; del1pid, del2pid: integer; scalex,scaley: real; begin rUser1[1] := 3; rUser1[2] := 8; rUser1[3] := 48; rUser1[4] := 59; rUser1[5] := 66; rUser1[6] := 80; n := nSlices; stkPid := pidNumber; GetPicSize(width, height); width := width - 4; perRow := 2; perCol := 3; SetNewSize(512,480); scalex := 512 / (perrow*width); scaley := 480 / (percol * height); if scalex > scaley then scalex := scaley else scaley := scalex; MakeNewWindow('montage'); montPid := PidNumber; x := 0; y := 0; for i := 1 to perRow * perCol do begin if x >= perRow then begin x := 0; y := y + 1; end; choosePic(stkPid); chooseSlice(rUser1[i]); killRoi; MakeRoi(0,0,width,height); Duplicate('deleteme'); del1pid := pidNumber; SetScaling('Bilinear,New Window'); ScaleAndRotate(scalex,scaley,0); del2pid := pidNumber; SelectAll; Copy; choosePic(montPid); makeRoi(x * width * scalex, y * height * scaley, width*scalex, height*scaley); paste; choosePic(del1pid); Dispose; choosePic(del2pid); Dispose; x := x + 1; end; end;